<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
/**
 * Tugh download Management System
 *
 * 基于CodeIgniter的下载管理系统
 * 
 * Tugh Download Management System is an open source multi-privilege  DM System built on the 
 * well-known PHP framework Codeigniter.
 *
 * @package		TDMS
 * @author		Tugh <tughluq@gmail.com>
 * @copyright	Copyright (c) 2010 - 2011, tughcms.com.
 * @license		GNU General Public License 2.0
 * @link		http://code.google.com/p/TDMS/
 * @version		0.0.1
 */
 
// ------------------------------------------------------------------------

/**
 * TDMS Dashboard Controller Class
 *
 * 控制台控制器
 *
 * @package		TDMS
 * @subpackage	Controller
 * @category	Admin Controller
 * @author		Tugh <tughluq@gmail.com>
 * @link 		http://code.google.com/p/TDMS
 */

class User extends TD_Auth_Controller {
		/**
     * 传递到对应视图的数据
     *
     * @access private
     * @var array
     */
	private $_data = array();

	 /**
     * 构造函数
     * 
     * @access public
     * @return void
     */
	public function __construct()
	{
		parent::__construct();
		
		$this->lang->load('main');	//导入语言文件
		
		$this->tank_auth->exceed('Administrator');	// 权限确认 
		
		/** 页面导航栏和标题 */
		$this->_data['page_title'] = $this->lang->line('user_manage');
		$this->_data['parentPage'] = 'dashboard';
		$this->_data['currentPage'] = 'user management';
		
		$this->load->model('tank_auth/users');
	}
	
	 /**
     * 默认执行函数
     * 
     * @access public
     * @return void
     */
	public function index()
	{
		redirect('/admin/user/userlist');
	}

	/**
     * 管理页面
     *
     * @access public
     * @param  int 	  $page   分页
     * @return void
     */
	public function userlist($page = 0)
	{

		$this->load->library('pagination');
		$this->load->library('uri');
		$config['base_url'] 		= base_url().'admin/user/search';
		$config['total_rows'] 		= $this->db->count_all('tugh_users');
		$config['per_page'] 		= '10'; 
		$config['uri_segment']		= '4';  // 表示第 3 段 URL 为当前页数，如 index.php/控制器/方法/页数，如果表示当前页的 URL 段不是第 3 段，请修改成需要的数值。
    	$config['first_link']		= 'First';
		$config['next_link']		= '<img class="paginationimg"  src="'.base_url().'public/images/pn.gif">';
		$config['prev_link']		= '<img class="paginationimg" src="'.base_url().'public/images/pp.gif">';
		$config['last_link']		= 'Last';
		
		$config['full_tag_open'] 	= '<table><tr>';
    	$config['full_tag_close']	= '</tr></table>';
		$config['cur_tag_open']		= '<td bgcolor="#5d7790">&nbsp;<font class="curpage"><b>';
		$config['cur_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['first_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['first_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['last_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['last_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['next_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['next_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['prev_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['prev_tag_close']	= '</b></font>&nbsp;</td>';
     	$config['num_tag_open']		= '<td bgcolor="" border="1">&nbsp;<font class="curpage"><b>';
    	$config['num_tag_close']	= '</b></font>&nbsp;</td>';
     	
		
		$this->pagination->initialize($config); 
		
		$this->_data['users'] = $this->users->get_users($config['per_page'],$this->uri->segment(4));
		$this->load->view('admin/user_manage',$this->_data);
	}
	
	/**
     * 搜索页面
     *
     * @access public
     * @param  void
     * @return void
     */
	public function search(){ 

		$this->load->library('pagination');
		$this->load->library('uri');
		
		$config['base_url'] 		= base_url().'admin/user/search';
		$config['total_rows'] 		= $this->db->count_all('tugh_users');
		$config['per_page'] 		= '1'; 
		$config['uri_segment']		= '4';  // 表示第 3 段 URL 为当前页数，如 index.php/控制器/方法/页数，如果表示当前页的 URL 段不是第 3 段，请修改成需要的数值。
    	$config['first_link']		= 'First';
		$config['next_link']		= '<img class="paginationimg"  src="'.base_url().'public/images/pn.gif">';
		$config['prev_link']		= '<img class="paginationimg" src="'.base_url().'public/images/pp.gif">';
		$config['last_link']		= 'Last';
		
		$config['full_tag_open'] 	= '<table><tr>';
    	$config['full_tag_close']	= '</tr></table>';
		$config['cur_tag_open']		= '<td bgcolor="#5d7790">&nbsp;<font class="curpage"><b>';
		$config['cur_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['first_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['first_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['last_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['last_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['next_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['next_tag_close']	= '</b></font>&nbsp;</td>';
    	$config['prev_tag_open']	= '<td bgcolor="">&nbsp;<font class="curpage"><b>';
    	$config['prev_tag_close']	= '</b></font>&nbsp;</td>';
     	$config['num_tag_open']		= '<td bgcolor="" border="1">&nbsp;<font class="curpage"><b>';
    	$config['num_tag_close']	= '</b></font>&nbsp;</td>';
     	
		
		$this->pagination->initialize($config); 
		
		if(!is_null($this->input->post('keyword',TRUE))){
			$keyword = $this->input->post('keyword',TRUE);
			$this->_data['users'] = $this->users->get_users_by_keyword($keyword);
			$this->load->view('admin/user_manage',$this->_data);
				
		}else{
			return false;
		}
	}
	
	/**
     * 管理页面
     *
     * @access public
     * @param  string $type 类型
     * @param  int 	  $mid  ID
     * @return void
     */
	public function manage($uid = NUll)
	{

		if($uid && is_numeric($uid))
		{
			$this->_data['uid'] = $uid;
			
			$user = $this->ci->users->get_user_by_id($uid);
			
			$meta = $this->metas_mdl->get_meta('BYID', $mid);
			
			$this->_data['name'] = $meta->name;
			$this->_data['slug'] = $meta->slug;
			$this->_data['description'] = $meta->description;
			
			
		}
		
		#$this->_operate($mid);
		
		$this->load->view('admin/manage_metas',$this->_data);
	}
	
}		
/* End of file main.php */
/* Location: ./application/controllers/admin/main.php */